package com.sc.web.controller.wx;

import com.sc.common.config.WxConfig;
import com.sc.common.core.domain.entity.WxUserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/wx")
public class WxLoginController {

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    WxConfig wxConfig;

    @RequestMapping("/login")
    public String wxLogin(@RequestBody WxUserInfo userInfo){
        ResponseEntity<String> wxUser = restTemplate.getForEntity(wxConfig.getUrl(), String.class, wxConfig.getAppid(), wxConfig.getSecret(), userInfo.getCode());

        return wxUser.getBody();
    }
}
